<?php
    $doc = new DOMDocument();
    $doc->load('http://habrahabr.ru/rss/');
    $arrFeeds = array();
    foreach ($doc->getElementsByTagName('item') as $node) {
        $itemRSS = array ( 
          'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
          'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
          'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
          'date' => date("Y-m-d H:i:s", strtotime($node->getElementsByTagName('pubDate')->item(0)->nodeValue)),
          );
        array_push($arrFeeds, $itemRSS);
    }

    $mysqli = new mysqli("mysql-88.ukraine.com.ua", "barthez_ai", "x9gedv4w", "barthez_ai");
    $mysqli->query("SET NAMES utf8");
    $mysqli->query("TRUNCATE TABLE rss");
    
    foreach($arrFeeds as $key=>$value) {
        $title = $arrFeeds[$key]['title'];
        $desc  = $arrFeeds[$key]['desc'];
        $link = $arrFeeds[$key]['link'];
        $date = $arrFeeds[$key]['date'];
        $created = date('Y-m-d H:i:s');
        $mysqli->query("INSERT INTO rss VALUES (NULL, 'http://habrahabr.ru/rss/', '$title', '$desc', '$link', '$date', '$created')");
    }
    
    $mysqli->close();
?>
